#include <stdio.h>
#include <stdlib.h>
#include "uart.h"
#define BUFFER_SIZE 50

int main(int argc, char *argv[])
{
    int fd;
    char buff[BUFFER_SIZE];
    // 输入参数:端口号,波特率，数据位，奇偶校验位(N)，停止位
    if (argc < 6)
    {
        printf("输入的参数不够");
        return -1;
    }

    if((fd = open_port(fd, atoi(argv[1]))) < 0){// 打开串口
        perror("open_port error");
        return -1;
    }
    if((set_opt(fd, atoi(argv[2]), atoi(argv[3]), *argv[4], atoi(argv[5]))) < 0){ //  设置串口
        perror("set_opt error");
        return -1;
    }
	do
	{
		printf("Input some words(enter 'quit' to exit):");
		memset(buff, 0, BUFFER_SIZE);
		if (fgets(buff, BUFFER_SIZE, stdin) == NULL)
		{
			perror("fgets");
			break;
		}
		write(fd, buff, strlen(buff));
	} while(strncmp(buff, "quit", 4));
    close(fd);
    return 1;
}
